package com.letv.whatslive.model.convert;

import com.letv.whatslive.model.Chips;
import com.letv.whatslive.model.CountryCode;
import com.letv.whatslive.model.utils.ObjUtils;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * Created by shenyue on 2016/7/5.
 */
public class CountryCodeConvert {
    public static DBObject castCountryCodeToDBObject(CountryCode countryCode) {
        DBObject dbo = new BasicDBObject();
        if (countryCode.getId() != null) {
            dbo.put("_id", countryCode.getId());
        }
        dbo.put("code", ObjUtils.toString(countryCode.getCode()));
        dbo.put("countryNameEnglish", ObjUtils.toString(countryCode.getCountryNameEnglish()));
        dbo.put("countryName", ObjUtils.toString(countryCode.getCountryName()));
        dbo.put("countryNamePinYin", ObjUtils.toString(countryCode.getCountryNamePinYin()));
        dbo.put("appId", ObjUtils.toLong(countryCode.getAppId()));
        dbo.put("createTime", ObjUtils.toLong(countryCode.getCreateTime(), 0l));
        return dbo;

    }

    public static CountryCode castDBObjectToCountryCode(DBObject dbObject) {
        CountryCode countryCode = new CountryCode();
        if (dbObject != null) {
            countryCode.setId(ObjUtils.toLong(dbObject.get("_id")));
            countryCode.setCode(ObjUtils.toString(dbObject.get("code")));
            countryCode.setCountryNameEnglish(ObjUtils.toString(dbObject.get("countryNameEnglish")));
            countryCode.setCountryName(ObjUtils.toString(dbObject.get("countryName")));
            countryCode.setCountryNamePinYin(ObjUtils.toString(dbObject.get("countryNamePinYin")));
            countryCode.setAppId(ObjUtils.toString(dbObject.get("appId")));
            countryCode.setCreateTime(ObjUtils.toLong(dbObject.get("createTime")));
        }

        return countryCode;
    }
}
